<?php
/**
 * Created by PhpStorm.
 * User: dx
 * Date: 17/7/6
 * Time: 下午16:23
 */
class UmengPushBind extends Eloquent
{
    protected $table = "u_meng_push_bind";
    protected $fillable = array("field_name","field_value");

    /*
     * @Author:      dx
     * @DateTime:    2017-07-06 16:42:29
     * @Description: field_name 代表推送者类型 目前仅为用户 方便扩展 分不同角色推送  user_id  代表推送给用户
     * 如果 field_name 值为user_id  那么 field_value 值则为 用户id
     * device_type 1-android 2-ios
     * */
    public static function bindDeviceToken($user_id,$device_token,$device_type){
        UmengPushBind::where("field_name","user_id")->where("field_value","!=",$user_id)->where("device_token",$device_token)->delete();
        $obj = UmengPushBind::firstOrNew(array("field_name" => "user_id","field_value"=> $user_id));
        $obj->device_token = $device_token;
        $obj->device_type = $device_type;

        return $obj->save();
    }
}
